package com.czg.jsonschema2lombokpojo;

import com.sun.codemodel.JExpressionImpl;
import com.sun.codemodel.JFormatter;
import org.apache.commons.lang.StringUtils;

/**
 * 产生一个安全的字符串值
 * @author czg
 */
public class JMyStringLiteral extends JExpressionImpl {
    public final String str;

    public JMyStringLiteral(String what) {
        this.str = what;
    }

    @Override
    public void generate(JFormatter f) {
        f.p("\"" + StringUtils.replace(str, "\"", "\\\"") + "\"");
    }
}
